'use strict';

let nunjucks = require('nunjucks');

function createEnv(path, opts) {

    path = path || 'views';
    opts = path || {};

    let s = {
        watch: opts.watch || true
    }

    let a = nunjucks.configure(path, s);
    return a;

}

module.exports = async (ctx, next) => {
    ctx.render = function (view, model) {
        let env = createEnv();
        ctx.body = env.render(view, model);
    }
    await next();
}